package com.stylefeng.guns.modular.system.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.Phoneset;
import com.stylefeng.guns.modular.system.service.IPhonesetService;

/**
 * 下发设置控制器
 *
 * @author fengshuonan
 * @Date 2018-10-08 19:12:58
 */
@Controller
@RequestMapping("/phoneset")
public class PhonesetController extends BaseController {

    private String PREFIX = "/system/phoneset/";

    @Autowired
    private IPhonesetService phonesetService;

    /**
     * 跳转到下发设置首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "phoneset.html";
    }

    /**
     * 跳转到添加下发设置
     */
    @RequestMapping("/phoneset_add")
    public String phonesetAdd() {
        return PREFIX + "phoneset_add.html";
    }

    /**
     * 跳转到修改下发设置
     */
    @RequestMapping("/phoneset_update/{phonesetId}")
    public String phonesetUpdate(@PathVariable Integer phonesetId, Model model) {
        Phoneset phoneset = phonesetService.selectById(phonesetId);
        model.addAttribute("item",phoneset);
        LogObjectHolder.me().set(phoneset);
        return PREFIX + "phoneset_edit.html";
    }

    /**
     * 获取下发设置列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return phonesetService.selectList(null);
    }

    /**
     * 新增下发设置
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(Phoneset phoneset) {
        phonesetService.insert(phoneset);
        return SUCCESS_TIP;
    }

    /**
     * 删除下发设置
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer phonesetId) {
        phonesetService.deleteById(phonesetId);
        return SUCCESS_TIP;
    }

    /**
     * 修改下发设置
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(Phoneset phoneset) {
        phonesetService.updateById(phoneset);
        return SUCCESS_TIP;
    }

    /**
     * 下发设置详情
     */
    @RequestMapping(value = "/detail/{phonesetId}")
    @ResponseBody
    public Object detail(@PathVariable("phonesetId") Integer phonesetId) {
        return phonesetService.selectById(phonesetId);
    }
}
